module japiserv
import StdEnv

prt :: !String !Int -> String
prt buf i= toString (toInt buf.[i])

/* 
loop :: !*File !String !Int -> *File
loop std buf i 
  | i >= (size buf) = fwrites "};\n" std 
  | i rem 20== 0
        # std= fwrites (",\n   "+++(prt buf i)) std
        = loop std buf (i+1) 
  # std= fwrites (","+++(prt buf i)) std 
  = loop std buf (i+1) 
*/

loop :: !*File !*File !Int -> (!*File, !*File)
loop std file n
  # (nd, file)= fend file
  | nd 
      # std= fwrites "};\n" std 
      = (std, file)
  | n> 20
      # std= fwritec '\n' std
      = loop std file 0
  # (ok, c, file)= freadc file
  # std= fwritec ',' std
  # std= fwritei (toInt c) std
  = loop std file (n+1)
  
where
  pr c= toString (toInt c)
  
Start world
  # (ok, file, world)= fopen "JAPI.jar" FReadData world
  # (ok, std, world)= fopen "japiserver.h" FWriteText world
  # aVISO=   "  bytecode gerado em Clean"
  # (n, file)= countbytes file 0 //freads file 600000
  # (ok, world)= fclose file world
  # (ok, file, world)= fopen "JAPI.jar" FReadText world
  # len= toString n
//  # (buf, file)= freads file n
  # (ok, file, world)= fopen "JAPI.jar" FReadData world
  # std= fwrites ("#define JAPISERVERLENGHT" +++
                         "        "+++len+++"\n\n\n") std
  # std=  fwrites "unsigned char JAPISERVER[] = {" std
  # (ok, c, file)= freadc file
  # std= fwritei (toInt c) std
  # (std, file)= loop std file 0
  # (ok, world)= fclose std world
  # (ok, world)= fclose file world
  = world

countbytes file n
   # (nd, file)= fend file
   | nd= (n, file)
   # (ok, _, file)= freadc file
   = countbytes file (n+1)